package com.woniuxy.myshop.intercepters;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PermissionIntercepter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object userInfo = request.getSession().getAttribute("userInfo");
        if(userInfo == null) {
            request.setAttribute("errorInfo","请先登录!");
            request.getRequestDispatcher("/login.html").forward(request,response);
            return  false ;
        }

        return true ;
    }
}
